from email.policy import default

from django.db import models
from django.template.defaulttags import comment


# Create your models here.


class Deptartment(models.Model):
    """部门表"""
    title = models.CharField(verbose_name="部门 ", max_length=48)

    def __str__(self):
        return self.title


class UserInfo(models.Model):
    """员工表"""
    name = models.CharField(verbose_name='姓名', max_length=48)
    password = models.CharField(verbose_name='密码', max_length=64)
    age = models.IntegerField(verbose_name='年龄')
    account = models.DecimalField(
        verbose_name='账户余额', max_digits=12, decimal_places=2, default=0)
    create_time = models.DateField(verbose_name='入职时间')
    # 无约束,如果插入的id，不存在于部门表中，那么这条记录根本查不到
    # depart_id = models.BigIntegerField(verbose_name='部门ID')
    # 1、有约束
    # - to,与哪张表关联
    # - to_field 表中的哪一列关联
    # 2、django自动
    # - 写的是depart,最后生成的字段是depart_id,django会帮我们自动处理好
    # depart = models.ForeignKey(to='Deptartment',to_field='id',on_delete=models.CASCADE)
    # 3、当部门表删除动作
    # - 3.1 用户表数据级联删除
    depart = models.ForeignKey(verbose_name='部门',
                               to='Deptartment', to_field='id', on_delete=models.CASCADE)
    # - 3.2 用户表数据置空
    # depart = models.ForeignKey(to='Deptartment', to_field='id',null=True,blank=True, on_delete=models.SET_NULL)

    # 在django中做约束
    gender_choices = (
        (0, '女'),
        (1, '男'),
        (2, '未知')
    )
    gender = models.SmallIntegerField(
        verbose_name='性别', choices=gender_choices)


class PrettyNum(models.Model):
    """靓号表"""
    mobile = models.CharField(verbose_name="手机号", max_length=11)  # 11位,后面要正则校验
    price = models.IntegerField(verbose_name="价格", default=0)  # 默认 0 元
    level_choices = (
        (1, '普通用户'),
        (2, '普通VIP'),
        (3, '普通SVIP'),
        (4, '高级SVIP'),
    )
    level = models.SmallIntegerField(
        verbose_name='级别', choices=level_choices, default=1)  # 默认等级 普通用户
    status_choices = (
        (1, '已占用'),
        (2, '未使用')
    )
    status = models.SmallIntegerField(
        verbose_name='状态', choices=status_choices, default=2)  # 默认 未使用


class Admin(models.Model):
    """管理员表"""
    username = models.CharField(verbose_name="用户名", max_length=32)
    password = models.CharField(verbose_name="密码", max_length=64)

    def __str__(self):
        return self.username


class Task(models.Model):
    """
        任务表
    """
    level_choices = (
        (1, "紧急"),
        (2, "重要"),
        (3, "普通"),
    )
    level = models.SmallIntegerField(verbose_name="级别", choices=level_choices, default=3,
                                     db_comment="任务级别")  # 默认 普通
    title = models.CharField(verbose_name="标题", max_length=64, db_comment="任务标题")
    information = models.TextField(verbose_name="描述信息", db_comment="任务的描述信息")
    user = models.ForeignKey(verbose_name="负责人", to=Admin, on_delete=models.CASCADE, db_comment="任务负责人")


class Order(models.Model):
    """
        订单表
        ID  订单号（20241018212395273148） 商品名称  价格 状态 用户ID
    """
    oid = models.CharField(verbose_name="订单号", max_length=64, db_comment="订单号")
    title = models.CharField(verbose_name="商品名称", max_length=64, db_comment="商品名称")
    price = models.DecimalField(verbose_name="价格", max_digits=12, decimal_places=2, db_comment="价格")
    status_choices = (
        (1, "待支付"),
        (2, "已支付")
    )
    status = models.SmallIntegerField(verbose_name="状态", choices=status_choices, default=1, db_comment="状态")
    user = models.ForeignKey(verbose_name="创建人", to=Admin, on_delete=models.CASCADE, db_comment="创建人-买家")


class Boss(models.Model):
    """
        老板=>Form
    """
    name = models.CharField(verbose_name="姓名", max_length=64, db_comment="姓名")
    age = models.IntegerField(verbose_name="年龄", db_comment="年龄")
    avatar = models.CharField(verbose_name="头像", max_length=64, db_comment="年龄")


class City(models.Model):
    """
        城市=>ModelForm
    """
    name = models.CharField(verbose_name="城市名称", max_length=64, db_comment="城市名称")
    count = models.IntegerField(verbose_name="人口", db_comment="人口")
    # 本质上在数据库中，也是CharField  字符串
    # 使用 FileField 会帮你自动保存数据
    # upload_to 它会帮你存到这里
    logo = models.FileField(verbose_name="Logo", max_length=64, db_comment="城市Logo",upload_to='city/%Y/%m/%d/')